layui.define(['layer','element', 'form','jquery','carousel'],function(exports) {
    var layer = layui.layer //弹层
        ,$ = layui.jquery
        ,form = layui.form
        ,carousel = layui.carousel;


var loginPage = {

    // init_carousel:function(){
    //     carousel.render({
    //         elem: '#test10'
    //         ,width: '961px'
    //         ,height: '650px'
    //         ,interval: 5000
    //     });
    //
    // },

    login:function () {
        form.on('submit(user_login)', function(data) {
            //REST风格 function(data) 因为submit监听了submitTable表单，data代表的是表单中的整体对象
            var username = $("#username").val();
            var password = $("#password").val();
            var captcha = $("#captcha").val();
            var remember = data.field.remember;

            if (remember === undefined) {
                remember = false;
            }else {
                remember = true;
            }
            $.ajax({
                type: "POST",
                contentType:"application/json",//post表单
                // contentType: "application/x-www-form-urlencoded",
                url: "/system/login",
                data: JSON.stringify({
                    username: username,
                    password: password,
                    captcha : captcha,
                    remember : remember
                }),
                // data: JSON.stringify({
                //     userName: username,
                //     userPassword: password,
                //     remember : remember
                // }),
                success:function(resp){
                    var code = resp.code;
                    if (code === 200 ){

                        // layer.msg('登录成功', {icon: 1});
                        //成功后跳转首页
                        window.location.href= "/index.html";

                    }else {
                        layer.msg("登录失败"+ " "+ resp.msg, {icon: 5});
                    //   验证码刷新待实现
                    }
                }
            });

            return false;
        });
    }


};

// loginPage.init_carousel();
loginPage.login();

exports("loginPage",loginPage);



});